package com.example.test622.ui.publish

import com.alibaba.android.arouter.facade.annotation.Route
import com.example.common.mvi.BaseView
import com.example.common.mvi.BaseViewModel
import com.example.test622.databinding.ActivityPublishBinding
import com.qiniu.pili.droid.shortvideo.PLAudioEncodeSetting
import com.qiniu.pili.droid.shortvideo.PLCameraSetting
import com.qiniu.pili.droid.shortvideo.PLFaceBeautySetting
import com.qiniu.pili.droid.shortvideo.PLMicrophoneSetting
import com.qiniu.pili.droid.shortvideo.PLRecordSetting
import com.qiniu.pili.droid.shortvideo.PLRecordStateListener
import com.qiniu.pili.droid.shortvideo.PLShortVideoRecorder
import com.qiniu.pili.droid.shortvideo.PLVideoEncodeSetting


@Route(path = ConstantValue.PUBLISH_PATH)
class PublishActivity : BaseView<ActivityPublishBinding,BaseViewModel<*,*>>(),PLRecordStateListener {
	lateinit var  mShortVideoRecorder:PLShortVideoRecorder
	
	override fun initView() {
		initRecorder()
	}

	private fun initRecorder() {
		mShortVideoRecorder =  PLShortVideoRecorder()
		mShortVideoRecorder.setRecordStateListener(this)
		
		// 摄像头采集选项
		val cameraSetting = PLCameraSetting()
		cameraSetting.setCameraId(PLCameraSetting.CAMERA_FACING_ID.CAMERA_FACING_FRONT)
		cameraSetting.setCameraPreviewSizeRatio(PLCameraSetting.CAMERA_PREVIEW_SIZE_RATIO.RATIO_4_3)
		cameraSetting.setCameraPreviewSizeLevel(PLCameraSetting.CAMERA_PREVIEW_SIZE_LEVEL.PREVIEW_SIZE_LEVEL_480P)


// 麦克风采集选项
		val microphoneSetting = PLMicrophoneSetting()


// 视频编码选项
		val videoEncodeSetting = PLVideoEncodeSetting(this)
		videoEncodeSetting.setEncodingSizeLevel(PLVideoEncodeSetting.VIDEO_ENCODING_SIZE_LEVEL.VIDEO_ENCODING_SIZE_LEVEL_480P_1) // 480x480
		videoEncodeSetting.setEncodingBitrate(1000 * 1024) // 1000kbps
		videoEncodeSetting.setEncodingFps(25)
		videoEncodeSetting.setHWCodecEnabled(true) // true:硬编 false:软编


// 音频编码选项
		val audioEncodeSetting = PLAudioEncodeSetting()
		audioEncodeSetting.setHWCodecEnabled(true) // true:硬编 false:软编


// 美颜选项
		val faceBeautySetting = PLFaceBeautySetting(1.0f, 0.5f, 0.5f)


// 录制选项
		val recordSetting = PLRecordSetting()
		recordSetting.setMaxRecordDuration((10 * 1000).toLong()) // 10s
		recordSetting.setVideoCacheDir("/sdcard")
		recordSetting.setVideoFilepath("/sdcard/record.mp4")
		
		
		mShortVideoRecorder.prepare(binding.glsPublish, cameraSetting, microphoneSetting,
			videoEncodeSetting, audioEncodeSetting, faceBeautySetting, recordSetting);
		
	}
	
	override fun initData() {
		
	
	}
	
	override fun onReady() {
	
	}
	
	override fun onError(p0: Int) {
	
	}
	
	override fun onDurationTooShort() {
	
	}
	
	override fun onRecordStarted() {
	
	}
	
	override fun onSectionRecording(p0: Long, p1: Long, p2: Int) {
	
	}
	
	override fun onRecordStopped() {
	
	}
	
	override fun onSectionIncreased(p0: Long, p1: Long, p2: Int) {
	
	}
	
	override fun onSectionDecreased(p0: Long, p1: Long, p2: Int) {
	
	}
	
	override fun onRecordCompleted() {
	
	}
	
}